const path = require('path')
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CompressionPlugin = require('compression-webpack-plugin')
export default {
  server: {
    port: 8000 // default: 3000
    // host: '0.0.0.0' // default: localhost
  },
  head: {
    // title: 'Kings`s Blog',
    // meta: [
    //   { charset: 'utf-8' },
    //   { name: 'viewport', content: 'width=device-width, initial-scale=1' },
    //   { hid: 'description', name: 'description', content: '' },
    //   { name: 'format-detection', content: 'telephone=no' }
    // ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ],
    script: [
      { src: 'https://cdn.jsdelivr.net/gh/forthespada/forthespada.github.io@master/plugin/click_heart.js' }
    ]
  },
  router: {
    extendRoutes: (routes, resolve) => {
      // routes.push({
      //   name: "article",
      //   path: '/article/:id',
      //   component: resolve(__dirname, 'pages/article/_id.vue')
      // })
    },
    // 切换页面让页面保持在顶部
    scrollBehavior (to, from, savedPosition) {
      return { x: 0, y: 0 }
    }
  },
  script: [

  ],
  css: [
    // 按需引入css
    'ant-design-vue/lib/grid/style/css',
    'ant-design-vue/lib/tag/style/css',
    'ant-design-vue/lib/icon/style/css',
    'ant-design-vue/lib/input/style/css',
    'ant-design-vue/lib/button/style/css',
    'ant-design-vue/lib/pagination/style/css',
    'ant-design-vue/lib/affix/style/css',
    'ant-design-vue/lib/form/style/css',
    'ant-design-vue/lib/form-model/style/css',
    'ant-design-vue/lib/avatar/style/css',
    'ant-design-vue/lib/empty/style/css',
    'ant-design-vue/lib/card/style/css',
    'ant-design-vue/lib/result/style/css',
    'ant-design-vue/lib/back-top/style/css',
    'ant-design-vue/lib/dropdown/style/css',
    'ant-design-vue/lib/menu/style/css',
    'ant-design-vue/lib/skeleton/style/css',
    'ant-design-vue/lib/message/style/css',
    'ant-design-vue/lib/popover/style/css',
    '~/assets/css/normailze.css',
    '~/assets/css/hover-min.css'
  ],
  plugins: [

    { src: '@/plugins/agile', ssr: false },
    { src: '@/plugins/antd-ui' },
    { src: '@/store/index', ssr: false },
    { src: '@/plugins/viewer', ssr: false },
    { src: '@/plugins/highlight', ssr: false }

  ],
  // 自动导入组件
  components: true,

  buildModules: [

  ],

  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    '@nuxtjs/proxy'

  ],
  // PWA module configuration: https://go.nuxtjs.dev/pwa
  pwa: {
    manifest: {
      lang: 'en'
    }
  },

  // Content module configuration: https://go.nuxtjs.dev/config-content
  content: {},
  proxy: {
    // 生产环境
    // '/portal/': {
    //   target: 'http://172.23.152.88:8082',
    // },
    // '/user/': {
    //   target: 'http://172.23.152.88:8082',
    // }
    // 测试环境
    // '/portal/': {
    //   target: 'http://60.205.178.38:80'
    // },
    // '/user/': {
    //   target: 'http://60.205.178.38:80'
    // }
    // 开发环境
    '/portal/': {
      target: 'http://localhost:8082'
    },
    '/user/': {
      target: 'http://localhost:8082'
    }
  },
  loading: { color: '#fff', height: '3px' },
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    extractCSS: true,
    // analyze: true,
    // 为防止重复打包
    vendor: ['axios'],
    analyza: {
      analyzeMode: 'static'
    },

    plugins: [
      // 内存占用大小查看
      // new BundleAnalyzerPlugin(),
      // gzip压缩
      new CompressionPlugin({
        test: /\.(js|css|png|jpg)(\?.*)?$/i, // 需要压缩的文件正则
        threshold: 10240, // 文件大小大于这个值时启用压缩
        deleteOriginalAssets: false // 压缩后保留原文件
      })
    ],
    assetFilter (assetFilename) {
      return assetFilename.endsWith('.js')
    },
    optimization: {
      splitChunks: {
        minSize: 10000,
        maxSize: 250000
      }
    },
    extend (config, {
      isDev,
      isClient
    }) {
      // 通过配置别名,处理图标过大问题,当请求这个@ant-design/icons/lib/dist$图标地址时，请求本地按需加载的icon.js
      config.resolve.alias['@ant-design/icons/lib/dist$'] = path.resolve(__dirname, './plugins/icons.js')
    },
    loaders: {
      less: {
        javascriptEnabled: true,
        modifyVars: {
          'primary-color': '#11659a', // 全局主色
          'secondary-color': '#B3D8FF', // 次主题色
          'hover-color': '#3f51b5', // 鼠标滑动色
          'icons-color': '#3f51b5', // icon图标颜色
          'primary-text': '#303133', // 字体主颜色
          'regular-text': '#606266'
        }
      }
    }
    // 开启打包分析
    // analyze: true,
    // assetFilter: function (assetFilename) {
    //   return assetFilename.endsWith('.js');
    // }
  }
}
